<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>es6基础语法</title>
  <script>
    /**
     * 1. 数组解构
     */
    function fun1(){
      let arr = [1,2,3,4,5]
      const [a,b,c,d,e] = arr
      console.log("a = ",a)
      console.log("b = ",b)
      console.log("c = ",c)
      console.log("d = ",d)
      console.log("e = ",e)
    }
    // fun1()
    /**
     * 2. 对象解构
     */
    function  fun2(){
      let stud = {
        "sid": 1001,
        "sname": '张三',
        "addr": '上海'
      }
      // 完整写法：
      // const {sid:sid1,sname:sname1,addr:addr1} = stud
      // console.log("sid: ",sid1);
      // console.log("sname: ",sname1);
      // console.log("addr: ",addr1);
      // 简化写法：(需要定义的变量名（key，即：号前的部分）与对象的属性名一致)
      const {sid,sname,addr} = stud
      console.log("sid: ",sid);
      console.log("sname: ",sname);
      console.log("addr: ",addr);
    }
    fun2()
  </script>
</head>
<body>

</body>
</html>
